#include"../include/p.h"
int create_tb(sqlite3* mydb,const char *tbname)
{
	char sql[100]="create table usermsg (id int primary key not null,name text,pwd text)";
	sprintf(sql,"create table %s (id int primary key not null,name text,pwd text)",tbname);
	printf("%s\n",sql);
	char str[200]={"table usermsg already exists"};
	sprintf(str,"table %s already exists",tbname);

	//sqlite3_exec(sqlite3 *db,const char *sql,sqlite3_callback
	//callback,void*,char**errmsg);
	//
	/*功能：执行SQL操作
	  db：数据库句柄
	  sql：SQL语句
	  callback：回调函数 第三和第四:再不使用select的使用,都为NULL
	  errmsg：错误信息指针的地址
	  返回值：成功返回0，失败返回错误码*/
	char *errmsg=NULL;//这里存储错误信息；
	int ret=sqlite3_exec(mydb,sql,NULL,NULL,&errmsg);
	if(ret!=SQLITE_OK&&strcmp(errmsg,"table usermsg already exists")!=0)
	{
		if(strcmp(tbname,"usermsg")!=0)	
		{
			if(strcmp(errmsg,str)==0)
			{
				printf("该表已存在～\n");
				return 0;
			}
		}
		printf("creat error:%s\n",errmsg);
		return -1;
	}
	printf("creat table ok\n");
	return 0;


}
